//
//  YPLoginUserInfo.m
//
//  Created by   on 2019/2/24
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "YPLoginUserInfo.h"

NSString *const bail = @"bail";
NSString *const card = @"card";
NSString *const head_url = @"head_url";
NSString *const idcard_img_down = @"idcard_img_down";
NSString *const idcard_img_hand = @"idcard_img_hand";
NSString *const idcard_img_up = @"idcard_img_up";
NSString *const income = @"income";
NSString *const is_dongjie = @"is_dongjie";
NSString *const is_res = @"is_res";
NSString *const is_share = @"is_share";
NSString *const jifen = @"jifen";
NSString *const jingpai_novice_num = @"jingpai_novice_num";
NSString *const jingpai_num = @"jingpai_num";
NSString *const keyong_bail = @"keyong_bail";
NSString *const keyong_yue = @"keyong_yue";
NSString *const last_login_time = @"last_login_time";
NSString *const loginKey = @"loginKey";
NSString *const mobile = @"mobile";
NSString *const name = @"name";
NSString *const nickname = @"nickname";
NSString *const p_uid = @"p_uid";
NSString *const password = @"password";
NSString *const reg_ip = @"reg_ip";
NSString *const reg_num = @"reg_num";
NSString *const reg_time = @"reg_time";
NSString *const shop_num_return = @"shop_num_return";
NSString *const uid = @"uid";
NSString *const user_guishu = @"user_guishu";
NSString *const user_type = @"user_type";
NSString *const yue = @"yue";
NSString *const chuangke_stauts = @"chuangke_stauts";

@interface YPLoginUserInfo ()
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
@end
@implementation YPLoginUserInfo
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.bail = [self objectOrNilForKey:bail fromDictionary:dict];
        self.card = [self objectOrNilForKey:card fromDictionary:dict];
        self.head_url = [self objectOrNilForKey:head_url fromDictionary:dict];
        self.idcard_img_down = [self objectOrNilForKey:idcard_img_down fromDictionary:dict];
        self.idcard_img_hand = [self objectOrNilForKey:idcard_img_hand fromDictionary:dict];
        self.idcard_img_up = [self objectOrNilForKey:idcard_img_up fromDictionary:dict];
        self.income = [self objectOrNilForKey:income fromDictionary:dict];
        self.is_dongjie = [self objectOrNilForKey:is_dongjie fromDictionary:dict];
        self.is_res = [self objectOrNilForKey:is_res fromDictionary:dict];
        self.is_share = [self objectOrNilForKey:is_share fromDictionary:dict];
        self.jifen = [self objectOrNilForKey:jifen fromDictionary:dict];
        self.jingpai_novice_num = [self objectOrNilForKey:jingpai_novice_num fromDictionary:dict];
        self.jingpai_num = [self objectOrNilForKey:jingpai_num fromDictionary:dict];
        self.keyong_bail = [self objectOrNilForKey:keyong_bail fromDictionary:dict];
        self.keyong_yue = [self objectOrNilForKey:keyong_yue fromDictionary:dict];
        self.last_login_time = [self objectOrNilForKey:last_login_time fromDictionary:dict];
        self.loginKey = [self objectOrNilForKey:loginKey fromDictionary:dict];
        self.mobile = [self objectOrNilForKey:mobile fromDictionary:dict];
        self.name = [self objectOrNilForKey:name fromDictionary:dict];
        self.nickname = [self objectOrNilForKey:nickname fromDictionary:dict];
        self.p_uid = [self objectOrNilForKey:p_uid fromDictionary:dict];
        self.password = [self objectOrNilForKey:password fromDictionary:dict];
        self.reg_ip = [self objectOrNilForKey:reg_ip fromDictionary:dict];
        self.reg_num = [self objectOrNilForKey:reg_num fromDictionary:dict];
        self.reg_time = [self objectOrNilForKey:reg_time fromDictionary:dict];
        self.shop_num_return = [self objectOrNilForKey:shop_num_return fromDictionary:dict];
        self.uid = [self objectOrNilForKey:uid fromDictionary:dict];
        self.user_guishu = [self objectOrNilForKey:user_guishu fromDictionary:dict];
        self.user_type = [self objectOrNilForKey:user_type fromDictionary:dict];
        self.yue = [self objectOrNilForKey:yue fromDictionary:dict];
        self.chuangke_stauts = [self objectOrNilForKey:chuangke_stauts fromDictionary:dict];
    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.bail forKey:bail];
    [mutableDict setValue:self.card forKey:card];
    [mutableDict setValue:self.head_url forKey:head_url];
    [mutableDict setValue:self.idcard_img_down forKey:idcard_img_down];
    [mutableDict setValue:self.idcard_img_hand forKey:idcard_img_hand];
    [mutableDict setValue:self.idcard_img_up forKey:idcard_img_up];
    [mutableDict setValue:self.income forKey:income];
    [mutableDict setValue:self.is_dongjie forKey:is_dongjie];
    [mutableDict setValue:self.is_res forKey:is_res];
    [mutableDict setValue:self.is_share forKey:is_share];
    [mutableDict setValue:self.jifen forKey:jifen];
    [mutableDict setValue:self.jingpai_novice_num forKey:jingpai_novice_num];
    [mutableDict setValue:self.jingpai_num forKey:jingpai_num];
    [mutableDict setValue:self.keyong_bail forKey:keyong_bail];
    [mutableDict setValue:self.keyong_yue forKey:keyong_yue];
    [mutableDict setValue:self.last_login_time forKey:last_login_time];
    [mutableDict setValue:self.loginKey forKey:loginKey];
    [mutableDict setValue:self.mobile forKey:mobile];
    [mutableDict setValue:self.name forKey:name];
    [mutableDict setValue:self.nickname forKey:nickname];
    [mutableDict setValue:self.p_uid forKey:p_uid];
    [mutableDict setValue:self.password forKey:password];
    [mutableDict setValue:self.reg_ip forKey:reg_ip];
    [mutableDict setValue:self.reg_num forKey:reg_num];
    [mutableDict setValue:self.reg_time forKey:reg_time];
    [mutableDict setValue:self.shop_num_return forKey:shop_num_return];
    [mutableDict setValue:self.uid forKey:uid];
    [mutableDict setValue:self.user_guishu forKey:user_guishu];
    [mutableDict setValue:self.user_type forKey:user_type];
    [mutableDict setValue:self.yue forKey:yue];
    [mutableDict setValue:self.chuangke_stauts forKey:chuangke_stauts];
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    self.bail = [aDecoder decodeObjectForKey:bail];
    self.card = [aDecoder decodeObjectForKey:card];
    self.head_url = [aDecoder decodeObjectForKey:head_url];
    self.idcard_img_down = [aDecoder decodeObjectForKey:idcard_img_down];
    self.idcard_img_hand = [aDecoder decodeObjectForKey:idcard_img_hand];
    self.idcard_img_up = [aDecoder decodeObjectForKey:idcard_img_up];
    self.income = [aDecoder decodeObjectForKey:income];
    self.is_dongjie = [aDecoder decodeObjectForKey:is_dongjie];
    self.is_res = [aDecoder decodeObjectForKey:is_res];
    self.is_share = [aDecoder decodeObjectForKey:is_share];
    self.jifen = [aDecoder decodeObjectForKey:jifen];
    self.jingpai_novice_num = [aDecoder decodeObjectForKey:jingpai_novice_num];
    self.jingpai_num = [aDecoder decodeObjectForKey:jingpai_num];
    self.keyong_bail = [aDecoder decodeObjectForKey:keyong_bail];
    self.keyong_yue = [aDecoder decodeObjectForKey:keyong_yue];
    self.last_login_time = [aDecoder decodeObjectForKey:last_login_time];
    self.loginKey = [aDecoder decodeObjectForKey:loginKey];
    self.mobile = [aDecoder decodeObjectForKey:mobile];
    self.name = [aDecoder decodeObjectForKey:name];
    self.nickname = [aDecoder decodeObjectForKey:nickname];
    self.p_uid = [aDecoder decodeObjectForKey:p_uid];
    self.password = [aDecoder decodeObjectForKey:password];
    self.reg_ip = [aDecoder decodeObjectForKey:reg_ip];
    self.reg_num = [aDecoder decodeObjectForKey:reg_num];
    self.reg_time = [aDecoder decodeObjectForKey:reg_time];
    self.shop_num_return = [aDecoder decodeObjectForKey:shop_num_return];
    self.uid = [aDecoder decodeObjectForKey:uid];
    self.user_guishu = [aDecoder decodeObjectForKey:user_guishu];
    self.user_type = [aDecoder decodeObjectForKey:user_type];
    self.yue = [aDecoder decodeObjectForKey:yue];
    self.chuangke_stauts = [aDecoder decodeObjectForKey:chuangke_stauts];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_bail forKey:bail];
    [aCoder encodeObject:_card forKey:card];
    [aCoder encodeObject:_head_url forKey:head_url];
    [aCoder encodeObject:_idcard_img_down forKey:idcard_img_down];
    [aCoder encodeObject:_idcard_img_hand forKey:idcard_img_hand];
    [aCoder encodeObject:_idcard_img_up forKey:idcard_img_up];
    [aCoder encodeObject:_income forKey:income];
    [aCoder encodeObject:_is_dongjie forKey:is_dongjie];
    [aCoder encodeObject:_is_res forKey:is_res];
    [aCoder encodeObject:_is_share forKey:is_share];
    [aCoder encodeObject:_jifen forKey:jifen];
    [aCoder encodeObject:_jingpai_novice_num forKey:jingpai_novice_num];
    [aCoder encodeObject:_jingpai_num forKey:jingpai_num];
    [aCoder encodeObject:_keyong_bail forKey:keyong_bail];
    [aCoder encodeObject:_keyong_yue forKey:keyong_yue];
    [aCoder encodeObject:_last_login_time forKey:last_login_time];
    [aCoder encodeObject:_loginKey forKey:loginKey];
    [aCoder encodeObject:_mobile forKey:mobile];
    [aCoder encodeObject:_name forKey:name];
    [aCoder encodeObject:_nickname forKey:nickname];
    [aCoder encodeObject:_p_uid forKey:p_uid];
    [aCoder encodeObject:_password forKey:password];
    [aCoder encodeObject:_reg_ip forKey:reg_ip];
    [aCoder encodeObject:_reg_num forKey:reg_num];
    [aCoder encodeObject:_reg_time forKey:reg_time];
    [aCoder encodeObject:_shop_num_return forKey:shop_num_return];
    [aCoder encodeObject:_uid forKey:uid];
    [aCoder encodeObject:_user_guishu forKey:user_guishu];
    [aCoder encodeObject:_user_type forKey:user_type];
    [aCoder encodeObject:_yue forKey:yue];
    [aCoder encodeObject:_chuangke_stauts forKey:chuangke_stauts];
}

- (id)copyWithZone:(NSZone *)zone {
    YPLoginUserInfo *copy = [[YPLoginUserInfo alloc] init];
    if (copy) {
        copy.bail = [self.bail copyWithZone:zone];
        copy.card = [self.card copyWithZone:zone];
        copy.head_url = [self.head_url copyWithZone:zone];
        copy.idcard_img_down = [self.idcard_img_down copyWithZone:zone];
        copy.idcard_img_hand = [self.idcard_img_hand copyWithZone:zone];
        copy.idcard_img_up = [self.idcard_img_up copyWithZone:zone];
        copy.income = [self.income copyWithZone:zone];
        copy.is_dongjie = [self.is_dongjie copyWithZone:zone];
        copy.is_res = [self.is_res copyWithZone:zone];
        copy.is_share = [self.is_share copyWithZone:zone];
        copy.jifen = [self.jifen copyWithZone:zone];
        copy.jingpai_novice_num = [self.jingpai_novice_num copyWithZone:zone];
        copy.jingpai_num = [self.jingpai_num copyWithZone:zone];
        copy.keyong_bail = [self.keyong_bail copyWithZone:zone];
        copy.keyong_yue = [self.keyong_yue copyWithZone:zone];
        copy.last_login_time = [self.last_login_time copyWithZone:zone];
        copy.loginKey = [self.loginKey copyWithZone:zone];
        copy.mobile = [self.mobile copyWithZone:zone];
        copy.name = [self.name copyWithZone:zone];
        copy.nickname = [self.nickname copyWithZone:zone];
        copy.p_uid = [self.p_uid copyWithZone:zone];
        copy.password = [self.password copyWithZone:zone];
        copy.reg_ip = [self.reg_ip copyWithZone:zone];
        copy.reg_num = [self.reg_num copyWithZone:zone];
        copy.reg_time = [self.reg_time copyWithZone:zone];
        copy.shop_num_return = [self.shop_num_return copyWithZone:zone];
        copy.uid = [self.uid copyWithZone:zone];
        copy.user_guishu = [self.user_guishu copyWithZone:zone];
        copy.user_type = [self.user_type copyWithZone:zone];
        copy.yue = [self.yue copyWithZone:zone];
        copy.chuangke_stauts = [self.chuangke_stauts copyWithZone:zone];
    }
    return copy;
}



/**
 是否是登录状态
 
 @return bool
 */
- (BOOL)isLogin {
    return (self.mobile.length > 0 && self.uid.length > 0 && self.loginKey.length > 0);
}

/**
 是否已经实名认证
 
 @return bool
 */
- (BOOL)isRealCertify {
    return (self.isLogin && self.card.length > 0 && [self.idcard_img_up containsString:@"http"] && [self.idcard_img_down containsString:@"http"] && [self.idcard_img_hand containsString:@"http"]);
}

/**
 是否可以申请成为创客

 @return true/false
 */
- (BOOL)canApply {
//    -1未申请0未处理1通过2驳回（-1和2可再次申请）
    if (![self isLogin]) {
        return false;
    }
    if ([self.chuangke_stauts intValue] == -1 || [self.chuangke_stauts intValue] == 2) {
        return true;
    }else {
        return false;
    }
}

/**
 创客文字
 
 @return title
 */
- (NSString *)applyTitle {
    if (![self isLogin]) {
        return @"成为创客";
    }
    if ([self.chuangke_stauts intValue] == -1 || [self.chuangke_stauts intValue] == 2) {
        return @"成为创客";
    }else if ([self.chuangke_stauts intValue] == 0) {
        return @"成为创客(审核中)";
    }else if ([self.chuangke_stauts intValue] == 1) {
        return @"您已成为创客";
    }else {
        return @"";
    }
}
@end
